/* Author: Qiao Yu
 * Date: 2011/4/1
 * With reference to : http://www.blogjava.net/dreamstone/archive/2007/08/05/134495.html
 */
package sjtu.edu.cn.se.compiler11.gui.errorview;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

public class ErrorTableViewer extends Composite{
	
	private Table table;
	private final TableViewer tableViewer;
	private List errorList = new ArrayList(); 
	
	public ErrorTableViewer(Composite parent)
	{
		super(parent,SWT.NONE);
	
	//	FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
	//	fillLayout.marginHeight = 0;
	//	fillLayout.marginWidth = 0;
	//	fillLayout.spacing = 1; 
		
	//	this.setLayout(fillLayout);
		
		tableViewer = new TableViewer(this, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER|SWT.V_SCROLL|SWT.H_SCROLL);		
		
	    table = tableViewer.getTable();
	    table.getHorizontalBar().setEnabled(true);
	    table.setLinesVisible(true);
	    table.setHeaderVisible(true);
	    table.setBounds(0, 0, 1260, 90);
	
	    final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);
	    newColumnTableColumn.setWidth(200);
	    newColumnTableColumn.setText("Description");

	    final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);
	    newColumnTableColumn_1.setWidth(85);
	    newColumnTableColumn_1.setText("Resource");
	    
	    final TableColumn newColumnTableColumn_2 = new TableColumn(table, SWT.NONE);
	    newColumnTableColumn_2.setWidth(80);
	    newColumnTableColumn_2.setText("Location");

	    final TableColumn newColumnTableColumn_3 = new TableColumn(table, SWT.NONE);
	    newColumnTableColumn_3.setWidth(100);
	    newColumnTableColumn_3.setText("Type");
	    
	    tableViewer.setContentProvider(new ContentProvider());
	    tableViewer.setLabelProvider(new TableLabelProvider());
	    tableViewer.setInput(getErrorInfo());
	    
	}
	
	public List getErrorInfo()
	{
		return errorList;
	}
	
	public void addErrorInfo(String des, String res, int loc, String type)
	{
		ErrorInfo newInfo = new ErrorInfo(des, res, loc, type);
		errorList.add(newInfo);
		tableViewer.refresh();
	}
	
	public void clear()
	{
		errorList.clear();
		tableViewer.refresh();
	}
}
